package org.dongchao.statistics.exe;

import java.util.List;

import org.dongchao.statistics.pojo.RequestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;

@Component
public class EmailRequestResultHandler implements RequestResultHandler {

	@Autowired
	JavaMailSender mailSender;

	@Value("${spring.mail.username}")
	String emailFrom;

	@Value("${spring.mail.emailTo}")
	String emailTo;

	@Override
	public void handler(List<RequestResult> result) {
		SimpleMailMessage message = new SimpleMailMessage();

		message.setFrom(emailFrom); // 必须要和上文配置的spring.mail.username内容相同
		message.setTo(emailTo);
		message.setSubject("git_commit_statistics");
		message.setText(JSON.toJSONString(result));
		mailSender.send(message);
	}

}
